package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/09/04 08:41
 **/
public class Day2_1_Num1582_NumSpecial {
    class Solution {
        public int numSpecial(int[][] mat) {
            int ans = 0;
            for(int i = 0; i < mat.length; ++i){
                for(int j = 0; j < mat[0].length; ++j){
                    if(mat[i][j] == 1){
                        if(isSpecial(mat, i , j)) {
                            ans++;
                        }
                    }
                }
            }
            return ans;
        }
        private boolean isSpecial(int[][] mat, int r, int c){
            for(int i = 0; i < mat.length; ++i){
                if(i == r) continue;
                if(mat[i][c] == 1) return false;
            }
            for(int j = 0; j < mat[0].length; ++j){
                if(j == c) continue;
                if(mat[r][j] == 1) return false;
            }
            return true;
        }
    }
}